import Vue from 'vue'
import App from './App.vue'
import router from './router'
import VueRouter from 'vue-router'
import store from './store'
//导入elementUI
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
// 导入axios
import axios from 'axios'
// 导入工具类
import commonUtils from '../src/utils/utils'

// 设置后端地址
axios.defaults.baseURL = "http://localhost:8086/";


axios.interceptors.response.use(response => {
  let res = response.data;
  // 如果是返回的文件
  if (response.config.responseType === 'blob') {
    return res
  }
  // 兼容服务端返回的字符串数据
  if (typeof (res) === 'string') {
    res = res ? JSON.parse(JSON.stringify(res)) : res
  }
  return res;
}, error => {
  // Do something with response error
  return Promise.reject(error);
});

//引用工具
Vue.prototype.axios = axios;
Vue.prototype.commonUtils = commonUtils;

// 解决ElementUI导航栏中的vue-router在3.0版本以上重复点菜单报错问题 
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
ElementUI.Drawer.props.wrapperClosable.default = false
Vue.use(ElementUI)
Vue.config.productionTip = false

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
